$(function(){
	getListByType(31);//竞价公告
	getListByType(41);//合同公示
	getListByType(21);//质疑
	getWorkList();//工作动态
	getNoticeList();//通知公告
	
	//查询功能
	$(".search_btn").click(function(){
		var key=$("#searchTitle").val();
		$("#title").val(key);//将值放入隐藏域中
		$("#currentPage").val(1);//将页码值为1
		$("#type").val("");//将项目详情值为空
		//initData();//查询请求
		//页面跳转
		window.location.href="../web/searchList?title="+key;
	});
});


function getListByType(Type){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice",
		data:{type:Type,pageSize:8},
		success: function(data){
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));//创建时间
				var endShowDate=new Date(Date.parse(data[i].endShowTime.replace(/-/g, "/")));//展示结束（开标时间）
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>30){
					title=title.substring(0,30)+'......';
				}
				if(data[i].isOpen==0){//未开标
					html+='<li title="'+top+'"><a href="getWebDetail?id='+data[i].id+'" target="_blank"><span class="left_title"><span class="no_open">•【未开标】</span>'+
					title+'</span><span class="right_time">'+endShowDate.Format("yyyy年MM月dd日")+'</span></a></li>'
				}else if(data[i].isOpen==1){
					html+='<li title="'+top+'"><a href="getWebDetail?id='+data[i].id+'" target="_blank"><span class="left_title"><span class="open">•【已开标】</span>'+
					title+'</span><span class="right_time">'+endShowDate.Format("yyyy年MM月dd日")+'</span></a></li>'
				}else if(data[i].isOpen==2){
					html+='<li title="'+top+'"><a href="getWebDetail?id='+data[i].id+'" target="_blank"><span class="left_title"><span class="no_open">•【正在公示】</span>'+
					title+'</span><span class="right_time">'+date.Format("yyyy年MM月dd日")+'</span></a></li>'
				}else if(data[i].isOpen==3){
					html+='<li title="'+top+'"><a href="getWebDetail?id='+data[i].id+'" target="_blank"><span class="left_title"><span class="open">•【公示结束】</span>'+
					title+'</span><span class="right_time">'+date.Format("yyyy年MM月dd日")+'</span></a></li>'
				}else {
					html+='<li title="'+top+'"><a href="getWebDetail?id='+data[i].id+'" target="_blank"><span class="left_title"><span class="open">• </span>'+
					title+'</span><span class="right_time">'+date.Format("yyyy年MM月dd日")+'</span></a></li>'
				}
			}
			$("#contentList_"+Type).html(html);
		},
		error: function(res){
			//alert(3);
		}
	});

}

function getWorkList(){
	$.ajax({
		type: "post",
		url:  "../web/getUnAutoNotice?type=51",
		success: function(data){
			var html='';
			for (var i = 0; i < data.length; i++) {
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>15){
					title=title.substring(0,15)+'......';
				}
					html+='<li title="'+top+'"><a target="_blank" href="getWebDetail?id='+data[i].id+'" ><span class="left_title">'+title+'</a></li>'
			}
			$("#contentList_work").html(html);
			
			jQuery(".txtMarquee-top").slide({
				mainCell : ".notice_main ul",
				autoPlay : true,
				effect : "topMarquee",
				vis : 5,
				interTime : 50,
				trigger : "click"
			});
		},
		error: function(res){
			//alert(3);
		}
	});

}

function getNoticeList(){
	$.ajax({
		type: "post",
		url:  "../web/getUnAutoNotice?type=52",
		success: function(data){
			var html='';
			for (var i = 0; i < data.length; i++) {
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>15){
					title=title.substring(0,15)+'......';
				}
					html+='<li title="'+top+'"><a target="_blank" href="getWebDetail?id='+data[i].id+'" ><span class="left_title">'+title+'</a></li>'
			}
			$("#contentList_notice").html(html);
			
			jQuery(".txtMarquee-top").slide({
				mainCell : ".ww ul",
				autoPlay : true,
				effect : "topMarquee",
				vis : 5,
				interTime : 50,
				trigger : "click"
			});
		},
		error: function(res){
			//alert(3);
		}
	});

}




/******************************公共工具方法*************************************/

/**
 * 时间格式化方法
 */
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, // 月份
        "d+": this.getDate(), // 日
        "h+": this.getHours(), // 小时
        "m+": this.getMinutes(), // 分
        "s+": this.getSeconds(), // 秒
        "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
        "S": this.getMilliseconds() // 毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

